<?php

//方便打印数组
function p($array)
{
    dump($array, 1, '<pre>', 0);
}
/**
 * 将debug内容写入文本文件  内容累加
 * */
function debug($txt, $info = '') {
	if ($txt == null || $txt == '') {
		$txt = '空数据';
	}
	$str = '';
	if (is_array ( $txt )) {
		$str = chr ( 10 ) . '识别出为数组 大小 ' . count ( $txt ) . $info . chr ( 10 );
		foreach ( $txt as $key => $value ) {
			if (! is_array ( $value )) { //如果直接是键值
				$str .= $key . '  =>  ' . $value . chr ( 10 );
			} else { //如果是子数组
				$str .= $key . '  =>  子数组  大小' . count ( $value ) . chr ( 10 );
				foreach ( $value as $key2 => $value2 ) {
					$str .= '      ' . $key2 . '  =>  ' . $value2 . chr ( 10 );
				}
			}
		}
		$file_pointer = fopen ( "debug.txt", "a+" );
		fwrite ( $file_pointer, $str );
		fclose ( $file_pointer );
		return;
	} else {
		$str = chr ( 10 ) . $info . '  ' . $txt . chr ( 10 );
	}
	$file_pointer = fopen ( "debug.txt", "a+" );
	fwrite ( $file_pointer, $str );
	fclose ( $file_pointer );
}
/**打印表格*/
function PrintTable($table) {
	
	if ($table == null || $table == '') {
		$str = '空数据';
	}
	$str = '<!DOCTYPE html><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	$str .= <<< END
 <style type="text/css">
    table {
  max-width: 100%;
  background-color: transparent;
  border-collapse: collapse;
  border-spacing: 0;

    border-left: 0;
    border-top:0;
    border: 1px solid #dddddd;
  -webkit-border-radius: 4px;
     -moz-border-radius: 4px;
          border-radius: 4px;
}

.table {
  width: 100%;
  margin-bottom: 20px;
}

.table th,
.table td {
  padding: 8px;
  line-height: 20px;
  font-size:14px;
  text-align: left;
  vertical-align: top;
  border-top: 1px solid #dddddd;
  border-left: 1px solid #dddddd;
  text-align:center;
}

.table th {
  font-weight: bold; color:#501d83; font-size:14px;
}
    </style>
     <div  style="display: table;line-height: 0; margin:0 auto; width:980px;">
<table class="table">
END;
	$rowsCount = count ( $table );
	//一维数组处理
	foreach ( $table as $key1 => $value1 ) {
		if (! is_array ( $value1 )) { //如果不是二维数组
			$str .= '<tr><th>键值</th><th>值</th>';
			$flag = 1;
			break;
		} else {
			$flag = 2;
			break;
		}
	}
	if ($flag == 1) //如果是一维数组
    {
		
		foreach ( $table as $key3 => $value3 ) {
			$str .= "<tr><td>$key3</td><td>$value3</td></tr>";
		}
	} else {
		//二维数组处理
		$str .= '<tr>';
		foreach ( $table [0] as $key => $value ) {
			$str .= "<th>$key</th>";
		}
		$str .= '</tr>';
		foreach ( $table as $key1 => $value1 ) {
			$str .= '<tr>';
			foreach ( $value1 as $key2 => $value2 ) {
				$str .= "<td>$value2</td>";
			}
			$str .= '</tr>';
		
		}
	}
	$str .= '</table><br/>数目'.$rowsCount.'</div></body></html>';
	$file_pointer = fopen ( "debug.htm", "w+" );
	fwrite ( $file_pointer, $str );
	fclose ( $file_pointer );
}
?>